package com.sen.design.pattern.creational.singleton;

/**
 * 懒汉式 (线程不安全)
 */
public class LazySingleton {
    private static LazySingleton lazySingleton = null;
    // 设置标志位。防止反射调用
    private static boolean flag = true;
    private LazySingleton(){
        if (flag){
            flag = false;
        }else {
            throw new RuntimeException("单例构造器禁止反射调用");
        }
    }
    public static LazySingleton getInstance(){

        if (lazySingleton == null){
            lazySingleton = new LazySingleton();
        }
        return lazySingleton;
    }

}

